 //some setup stuff
google.load("language", "1");
google.setOnLoadCallback(init);

//init funtion
function init() {
   var src = document.getElementById('src');
   var dst = document.getElementById('dst');
   var i = 0;
   for (l in google.language.Languages) {
      var lng = l.toLowerCase();
      var lngCode = google.language.Languages[l];
      if (google.language.isTranslatable(lngCode)) {
         src.options.add(new Option(lng, lngCode));
         dst.options.add(new Option(lng, lngCode));
         }
      }
   google.language.getBranding('branding', {
      type : 'vertical' }
   );
   submitChange();
}
   
//submit change funtion
function submitChange() {
   var value = document.getElementById('source').value;
   var src = document.getElementById('src').value;
   var dest = document.getElementById('dst').value;
   google.language.translate(value, src, dest, translateResult);
   return false;
}
   
//translate result function
function translateResult(result) {
   var resultBody = document.getElementById("results_body");
   if (result.translation) {
      var str = result.translation.replace('>', '&gt;').replace('<', '&lt;');
      resultBody.innerHTML = str;
      }
   else {
      resultBody.innerHTML = '<span style="color:red">Error Translating</span>';
      }
}

